<?php 
require 'db.php';

if(isset($_POST['manhom']))$manhom=$_POST['manhom'];
if(isset($_POST['masv']))$masv=$_POST['masv'];

//====================================================
	if(isset($_POST['mamon'])) $mamon=$_POST['mamon'];
	$noidung = array();
	$sqldk="SELECT  dbo_dondangky.MANHOM,TENNHOM,SISOTOIDA,SISOTOIDA-count(MASV) as SVDKT,TENMH ";
	$sqldk.=" from dbo_noidung,dbo_dondangky,dbo_monhoc where dbo_noidung.MAMH=:mamh and dbo_noidung.MANHOM=dbo_dondangky.MANHOM and dbo_monhoc.MAMH=dbo_noidung.MAMH ";
	$sqldk.=" group by MANHOM";
	$sqldk.=" union (";
	$sqldk.=" SELECT  MANHOM,TENNHOM,SISOTOIDA,SISOTOIDA as SVDKT,TENMH ";
	$sqldk.=" from dbo_noidung,dbo_monhoc where dbo_noidung.MaMH=:mamh and dbo_monhoc.MAMH=dbo_noidung.MAMH  and  MANHOM not in ( ";
	$sqldk.=" SELECT  dbo_dondangky.MANHOM ";
	$sqldk.=" from dbo_noidung,dbo_dondangky,dbo_monhoc where dbo_noidung.MaMH=:mamh and dbo_noidung.MANHOM=dbo_dondangky.MANHOM and dbo_monhoc.MAMH=dbo_noidung.MAMH )) ";
	$stmt = $db->prepare($sqldk);
	$stmt->bindParam("mamh",$mamon,PDO::PARAM_STR);
	$stmt->execute();
	$stmt->execute();
	if($stmt->execute()){
	while($r=$stmt->fetch()){
		$noidung=array_merge($noidung,array(
				array("MANHOM"=>$r['MANHOM'],"TENNHOM"=>$r['TENNHOM'],"SISOTOIDA"=>$r['SISOTOIDA'],"SVDKT"=>$r['SVDKT'],"TENMH"=>$r['TENMH'])
		));
	}}
//==================================================== 
?>
<div id="khungmonthi">
  <table  class="table table-bordered table-hover" style="font-size: 13px;">
    <thead>
      <tr class="info">
	  	<th>STT</th>  
		<th>Mã Nhóm </th> 
        <th>Môn thể thao </th>
        <th>Nội dung thi đấu </th>
       	<th>Chọn nhóm</th>

      </tr>
    </thead>
    <tbody>
		<?php $i=1;
			  foreach($noidung as $nd){?>
      <tr>
	  	<td><?php echo $i++;?></td>
        <td><?php echo $nd['MANHOM'];?></td>
        <td><?php echo $nd['TENMH'];?></td>
		<td><?php echo $nd['TENNHOM'];?></td>
        <td>
			<?php 
		echo"<input type='radio' name='rdMHd' id='rdDKMonThid' value='".$nd['MANHOM']."'  title='Nhấp chuột vào đây để xem thông tin chi tiết của các đội của môn thể thao thi đấu.'>";
			?>
		</td>
        <?php }?>
      </tr>
    </tbody>
    <tfoot>
      <tr>
      </tr>
    </tfoot>
  </table>
  <hr />
</div>

